<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:replace="common/base::pagetitle"></title>
    <link th:replace="common/base::static"/>
</head>
<style type="text/css">
    .layui-table-cell{
        height: inherit;
        white-space: normal;
        vertical-align:top;
    }
    /**表头文字样式*/
    .layui-table th{
        font-weight: bold;
        font-size: 14px;
        text-align: center;
    }
    /**表格文字样式*/
    .layui-table td{
        font-size: 13px;
        text-align: center;
    }
</style>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
    <div class="layui-row">
        <div class="layui-col-md12" id="kMainContentCol">
            <div class="layui-fluid kvf-fluid-padding15">
                <div class="layui-card">
                    <form>
                        <div class="layui-form layui-card-header kvf-card-header-auto">
                            <div class="layui-form-item">
                            </div>
                        </div>
                    </form>

                    <div class="layui-card-body">
                        <table id="kContentTable" lay-filter="kContentTable"></table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>

<!--头部工具栏模板-->
<script type="text/html" id="headToolbarTpl">
    <button type="button" lay-event="batchdel" class="layui-btn layui-btn-sm layui-btn-danger" ><i class="layui-icon layui-icon-delete"></i>删除</button>
    <button type="button" lay-event="editStatus" class="layui-btn layui-btn-sm layui-btn-normal" ><i class="layui-icon layui-icon-edit"></i>设置为已联系</button>
    <button type="button" lay-event="editnoStatus" class="layui-btn layui-btn-sm layui-btn-danger" ><i class="layui-icon layui-icon-edit"></i>设置为未联系</button>
    <button type="button" data-event="refresh" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-refresh"></i>刷新</button>
</script>

<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
    <!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
</script>

<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'form', 'layer', 'table', 'laydate'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table, laydate = layui.laydate;
        var tableId = 'kContentTable';
        var area = ['449px', '95%'];

        // 实例化table
        var tableIns = table.render($.extend(config.layui.table, {
            elem: '#' + tableId
            ,url: BASE_WEB + 'xhs/intentionCust/list/data' // 数据接口
            ,toolbar: '#headToolbarTpl'
            ,even: true //隔行换色
            ,cols: [[ //表头
                {type:'checkbox',Width: 70,unresize: true}
                ,{field: 'taskName', title: '任务名称', Width: 100,unresize: true}
                ,{field: 'videoLink', title: '详情链接',Width: 150,unresize: true,templet: function(d){
                        return '<a href='+d.videoLink+' style="color: blue" target="_blank">'+d.label+'</a>'
                    }}
                ,{field: 'custAvatar', title: '客户头像', Width: 90,align:'center',unresize: true, templet:function (d) {
                        return '<img src="'+d.custAvatar+'" onclick="showimg(this)" title="点我" width="35" height="35"/>'}}
                ,{field: 'nickname', title: '客户网名', Width: 121,unresize: true}
                //,{field: 'taskId', title: '关联任务id', Width: 130}

                ,{field: 'content', title: '咨询内容', Width: 130,unresize: true}
                ,{field: 'hitKeyword', title: '命中关键词', Width: 109,unresize: true}
                ,{field: 'consuTime', title: '咨询时间', Width: 105,unresize: true,sort: true}
                ,{field: 'analyseTime', title: '分析时间', Width: 160,unresize: true,sort: true}
                ,{field: 'label', title: '说明', Width: 150,unresize: true}
                ,{field: 'vx', title: '微信号', Width: 85,unresize: true,templet: function(d){
                        if(d.vx==null){
                            return '-'
                        }else if(d.vx!=null) {
                            return d.vx
                        }}}
                ,{field: 'cusPhone', title: '手机号', Width: 85,unresize: true,templet: function(d){
                        if(d.cusPhone==null){
                            return '-'
                        }else if(d.cusPhone!=null) {
                            return d.cusPhone
                        }}}
                //,{field: 'custHome', title: '客户主页链接', width: 150}
                ,{field: 'status', title: '状态', width: 102,sort: true,unresize: true,templet: function(d){
                        if(d.status==0){
                            return '<span style="color: #FF3366;font-size: 13px;">未联系</span>'
                        }else if(d.status==1) {
                            return '<span style="color: #00B83F;font-size: 13px;">已联系</span>'
                        }}}
                //,{field: 'createTime', title: '创建时间', Width: 150}
                //,{field: 'createUser', title: '创建人', Width: 130}
                //,{field: 'updateTime', title: '修改时间', Width: 130}
                //,{field: 'updateUser', title: '修改人', Width: 130}

                ,{field: 'custHome', title: '私信客户', Width: 150,unresize: true,templet: function(d){
                        return '<a href='+d.custHome+' style="color: blue" target="_blank"><button type="button" class="layui-btn layui-btn-sm">私信客户</button></a>'
                    }}
                //,{field: '', title: '操作', width: 235, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
        }));









        // 监听表格头部事件
        table.on('toolbar(' + tableId + ')', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var checkData = checkStatus.data; // 得到选中的数据
            switch(obj.event) {
                case 'editStatus':
                    if(checkData.length === 0){
                        return kvfKit.warningMsg('请选择数据');
                    }
                    var ids = [];
                    $.each(checkData, function(i, n){
                        ids[i] = n.id;
                    });

                    //执行 Ajax 后重载
                    $.ajax({
                        type: req.type.post,
                        url: BASE_WEB + 'xhs/intentionCust/editStatus',
                        data: {ids: ids.toString()},
                        success: function (r) {
                            if (r.code === req.status.ok) {
                                table.reload(tableId);
                                kvfKit.sucessMsg('已修改');
                            } else {
                                kvfKit.errorMsg(r.msg);
                            }
                        }
                    });
                    break;
                case 'editnoStatus':
                    if(checkData.length === 0){
                        return kvfKit.warningMsg('请选择数据');
                    }
                    var ids = [];
                    $.each(checkData, function(i, n){
                        ids[i] = n.id;
                    });

                    //执行 Ajax 后重载
                    $.ajax({
                        type: req.type.post,
                        url: BASE_WEB + 'xhs/intentionCust/editnoStatus',
                        data: {ids: ids.toString()},
                        success: function (r) {
                            if (r.code === req.status.ok) {
                                table.reload(tableId);
                                kvfKit.sucessMsg('已修改');
                            } else {
                                kvfKit.errorMsg(r.msg);
                            }
                        }
                    });
                    break;
                case 'batchdel':
                    if(checkData.length === 0){
                        return kvfKit.warningMsg('请选择数据');
                    }
                    layer.confirm('确定删除吗？', function(index) {
                        var ids = [];
                        $.each(checkData, function(i, n){
                            ids[i] = n.id;
                        });

                        //执行 Ajax 后重载
                        $.ajax({
                            type: req.type.post,
                            url: BASE_WEB + 'xhs/intentionCust/batchdel',
                            data: {ids: ids.toString()},
                            success: function (r) {
                                if (r.code === req.status.ok) {
                                    table.reload(tableId);
                                    kvfKit.sucessMsg('已删除');
                                } else {
                                    kvfKit.errorMsg(r.msg);
                                }
                            }
                        });
                    });
                    break;
            }
        });




        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            renderTableData(obj.field);
            return false;
        });

        var active = {
            refresh: function () {
                var $form = $('form');
                $form[0].reset();
                renderTableData(kvfKit.getFormJson($form));
            }
        };

        kvfKit.activeInit(active);

        function renderTableData(params) {
            params = params ? params : {};

            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
        }

        // 绑定监听回车事件
        kvfKit.bindEnterEventForLayuiForm();

    });



    //点解图片放大
    window.showimg = function (t) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: '716px',
            skin: 'layui-layer-nobg',
            shadeClose: true,
            content: '<img style="display: inline-block; width: 100%; height: 100%;" src="' + t.src + '">'
        });
    }
</script>

</body>
</html>